import java.util.LinkedList;
import java.util.List;

public class BruteForceSolution {
    public int totalFruit(int[] fruits) {
        int n = fruits.length;
        int max = 0;//最多能放的水果的个数
        List<Integer> list = new LinkedList<>();//放水果类型
        for (int i = 0; i < n; i++) {
            int count = 1;
            list.add(fruits[i]);
            for (int j = i + 1; j < n; j++) {
                if (list.contains(fruits[j])) {
                    count++;
                } else {
                    if (list.size() == 2) {
                        break;
                    } else {
                        count++;
                        list.add(fruits[j]);
                    }
                }
            }
            max = Math.max(count, max);
            list.clear();
        }
        return max;
    }
}
